public class LongestCommonPrefix {

    public static void main(String[] args) {

    }

    public static String longestCommonPrefix(String[] strs) {
        String prefix = strs[0];
        for(int i=1;i < strs.length;i++) {
            StringBuilder newPrefix = new StringBuilder();
            for(int j=0;j < prefix.length() && j < strs[i].length();j++) {
                if(prefix.charAt(j) != strs[i].charAt(j)) {
                    break;
                }
                newPrefix.append(prefix.charAt(j));
            }
            prefix = newPrefix.toString();
        }
        return prefix;
    }
}
